<template>
	<view>
		<!-- 		<view style="width: 100%; ">
			<u--image src="/static/bg_login.png" ></u--image>
		</view> -->
		<u--image src="/static/bg_login.png" width="100%" height="400rpx"></u--image>
		<u--text text="用户名或手机号" :bold="true" customStyle="margin: 50px 0px 0px 50rpx"></u--text>
		<u--input v-model="nameValue" customStyle="margin: 10px 50px 0px 50rpx" placeholder="请输入您的账户" border="bottom"
			clearable>
		</u--input>

		<u--text text="密码" :bold="true" customStyle="margin: 30px 0px 0px 50rpx"></u--text>
		<u--input v-model="pwdValue" customStyle="margin: 10px 50px 0px 50rpx" placeholder="请输入您的密码" border="bottom"
			clearable>
		</u--input>

		<view>
			<u-button class="custom-style" type="primary" text="登录" @click="clickLogin"></u-button>
		</view>
		<view>
			<u-button class="custom-style-register" type="info" text="前去注册"  @click="clickRegister"></u-button>
		</view>



	</view>
</template>

<script>
	export default {
		data() {
			return {
				nameValue: uni.getStorageSync('user_name'),
				pwdValue: '',
			}
		},
		methods: {

			clickLogin() {
				// this.$u.toast(this.nameValue)
				let param = {
					userPhone: this.nameValue,
					password: this.pwdValue
				}
				this.$u.api.apiLogin(param).then(res => {
					if (res.code == 1) {
						this.$u.toast("登陆成功!")
						// 保存全局登陆名
						uni.setStorage({
							key: 'user_name',
							data: this.nameValue,
							success() {
								console.log("保存登陆用户名成功!")
							}
						})
						// 保存全局登陆名
						uni.setStorage({
							key: 'user_head',
							data: res.data.userHead,
							success() {
								console.log("保存登陆用户头像成功!")
							}
						})
						console.log("token", res.data.token)
						
						// this.$u.route('pages/index/index', {
						// 	login_token: res.data.token,
						// });
						
						// 保存全局token
						uni.setStorage({
							key: 'login_token',
							data: res.data.token,
							success() {
								console.log("token1", uni.getStorageSync('login_token'))
								//返回上一页
								uni.navigateBack({
									login_token:res.data.token
								});
								
								// uni.$u.route({
								// 	url: 'pages/mine/mine',
								// })
								
								// uni.navigateTo({
								// 	url:'pages/order/order'
								// })
								
								// uni.$u.route({
								// 	url: "pages/index/index",
								// })
								
								// uni.$u.route('pages/mine/mine', {
								// 	login_token: res.data.token,
								// });
								
							}
						})
					} else {
						uni.$u.toast(res.msg);
					}
				})
			},
			clickRegister(){
				uni.$u.route({
					url: 'pages/login/register',
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.custom-style {
		width: 80%;
		margin-top: 100rpx;
	}

	.custom-style-register {
		width: 80%;
		margin-top: 50rpx;
	}
</style>
